/**
 * 
 */
package com.cqcis.uip.module.salary.oper.service.impl.course;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.cqcis.uip.module.salary.oper.SalaryConstants;
import com.cqcis.uip.module.salary.oper.dao.CourseRealRecordDao;
import com.cqcis.uip.module.salary.oper.domain.Employe;
import com.cqcis.uip.module.salary.oper.domain.SalaryMain;
import com.cqcis.uip.module.salary.oper.domain.SalaryTrusteeshipDetail;
import com.cqcis.uip.module.salary.oper.domain.extend.Trusteeship;
import com.cqcis.uip.module.salary.oper.service.TrusteeshipService;

/**
 * @author 李世军
 *
 * 创建于 2012-3-21 下午03:36:18
 */
public class TrusteeshipServiceImpl implements TrusteeshipService {
	@SuppressWarnings("unused")
	private static Log log = LogFactory.getLog(TrusteeshipServiceImpl.class);
	private CourseRealRecordDao courseRealRecordDao ;
	
	public void setCourseRealRecordDao(CourseRealRecordDao courseRealRecordDao) {
		this.courseRealRecordDao = courseRealRecordDao;
	}

	/* (non-Javadoc)
	 * @see com.cqcis.uip.module.salary.oper.service.TrusteeshipService#setSalary(com.cqcis.uip.module.salary.oper.domain.Employe, com.cqcis.uip.module.salary.oper.domain.SalaryMain, java.util.List)
	 */
	public void setSalary(Employe e, SalaryMain main, List<SalaryTrusteeshipDetail> details) {
		// --教师
		List<Trusteeship> trusteeships = courseRealRecordDao.findTrusteeship(e.getId()) ;
		if(trusteeships!=null && trusteeships.size()>0){
			for(Trusteeship trusteeship : trusteeships){
				SalaryTrusteeshipDetail detail = new SalaryTrusteeshipDetail() ;
				detail.setEmploye_id(e.getId()) ;
				detail.setStudent_id(trusteeship.getStudent_id()) ;
				detail.setGrade_id(trusteeship.getGrade_id()) ;
				detail.setCourse_id(trusteeship.getCourse_id()) ;
				detail.setDays(trusteeship.getDays()) ;
				details.add(detail) ;
			}
			
			// 设置价格
			float total = 0F ;
			for(SalaryTrusteeshipDetail dtl : details ){
				//if(dtl.getDays()>=SalaryConstants.TRUSTEESHIP_DAYS){
					dtl.setFee(SalaryConstants.TRUSTEESHIP_RATIOS.get(dtl.getGrade_id())/22*dtl.getDays()) ;
//				}else{
//					dtl.setFee(0F) ;
//					dtl.setRemark("托管天数未达到"+SalaryConstants.TRUSTEESHIP_DAYS) ;
//				}
				total += dtl.getFee() ;
			}
			
			// 设置总价
			main.setTrusteeship_fee(total) ;
		}
		
		
		// --学管师
		List<Trusteeship> trusteeshipsMs = courseRealRecordDao.findTrusteeshipSm(e.getId()) ;
		if(trusteeshipsMs!=null && trusteeshipsMs.size()>0){
			for(Trusteeship trusteeshipMs : trusteeshipsMs){
				SalaryTrusteeshipDetail detail = new SalaryTrusteeshipDetail() ;
				detail.setEmploye_id(e.getId()) ;
				detail.setStudent_id(trusteeshipMs.getStudent_id()) ;
				detail.setGrade_id(trusteeshipMs.getGrade_id()) ;
				detail.setCourse_id(trusteeshipMs.getCourse_id()) ;
				detail.setDays(trusteeshipMs.getDays()) ;
				details.add(detail) ;
			}
			
			// 设置价格
			float total = 0F ;
			for(SalaryTrusteeshipDetail dtl : details ){
//				if(dtl.getDays()>=SalaryConstants.TRUSTEESHIP_DAYS){
					dtl.setFee(SalaryConstants.TRUSTEESHIP_RATIO_SM/22*dtl.getDays()) ;
//				}else{
//					dtl.setFee(0F) ;
//					dtl.setRemark("托管天数未达到"+SalaryConstants.TRUSTEESHIP_DAYS) ;
//				}
				total += dtl.getFee() ;
			}
			
			// 设置总价
			main.setTrusteeship_fee(total) ;
		}
	}

}
